package com.xca.znb.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class GoodsDBHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = "goods.db" ;
    private static final int DATABASE_VERSION = 1 ;

    public static final String TABLE_GOODS = "goods" ;
    public static final String GOODS_ID = "id" ;
    public static final String GOODS_NAME = "name" ;
    public static final String GOODS_FIRST_IMG = "first_image" ;
    public static final String GOODS_IMG_LIST = "img_list" ;
    public static final String GOODS_TYPE = "type" ;
    public static final String GOODS_PRICE = "price" ;
    public static final String GOODS_UNIT = "unit" ;
    public static final String GOODS_FREIGHT = "freight" ; //运费
    public static final String GOODS_ADDRESS = "address" ; //发货地址
    public static final String GOODS_TEXT = "text" ; //描述
    public static final String GOODS_PUBLISHER = "publisher" ; //发布者
    public static final String GOODS_STATE = "state" ; //状态，上架/下架

    private static final String CREATE_TABLE_GOODS = "CREATE TABLE " + TABLE_GOODS + " ( " +
            GOODS_ID + " INTEGER PRIMARY KEY AUTOINCREMENT , " +
            GOODS_NAME + " TEXT , " +
            GOODS_FIRST_IMG + " TEXT , " +
            GOODS_IMG_LIST + " TEXT , " +
            GOODS_TYPE + " TEXT , " +
            GOODS_PRICE + " DOUBLE , " +
            GOODS_UNIT + " TEXT ," +
            GOODS_FREIGHT + " TEXT ," +
            GOODS_ADDRESS + " TEXT , " +
            GOODS_TEXT + " TEXT , " +
            GOODS_PUBLISHER + " TEXT ," +
            GOODS_STATE + " TEXT )" ;


    public GoodsDBHelper(@Nullable Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE_GOODS);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_GOODS);

    }
}
